<?php

/**
 * @Author: kendy
 * @Date:   2019-12-27 10:16:58
 * @Last Modified by:   jiayanting
 * @Last Modified time: 2020-03-27 17:13:33
 */
namespace app\api\controller; 
use think\Model;
use think\Db;  
use think\Request; 
use app\common\model\AppraiseModel as am; 	
class Introduce extends Nocommon
{

 public function getStoreIntroduce()
   {
	   	//type 1景点，2酒店，3跟团，
/*	   	 $result['introduce'] = '';
	   	 $result['images'] = '';
	   	 $result['app'] = [];*/
	   	// $res =  $am->getAppList(2,1,1,'','',true); 
   	 	if(Request::instance()->isPost()){  
   	 	  $am = new am();
          $type = (int)input('post.type'); 
          $item_id = (int)input('post.item_id'); 
          $eval_status = (int)input('post.eval_status');
          $isImages = false;
          if($eval_status == 3){
             $isImages = true;
          }   
          if(empty($type))
          	  return $this->apiReturn('400','类型为空',0);
         if(empty($item_id))
          	  return $this->apiReturn('400','对象id为空',0); 
          $page = $this->p(); 
          $limit = input('post.limit/d');  
          if($type==1)
          {
          	 $result = Db::name('tours')
          	 ->field('tour_subject as introduce')
          	 ->where(['is_del'=>0,'is_pass'=>1,'tour_id'=>$item_id,'is_display'=>0])
          	 ->find();
             if(!empty($result)){
                $imagesArr = Db::name('tour_img')
                ->where('tour_id',$item_id)
                ->order('sort desc')
                ->select();
                if(empty($result['images']))$result['images'] = [];
                if(count($imagesArr)>0)
                {
                   foreach ($imagesArr as $key => $value) {
                    if($value['img_path'])
                      $result['images'][] =  addWaterByField($value['img_path']);
                   }
                }
             }
          }
          if($type==2)
          {
          	 $result = Db::name('hotel')
          	 ->field('hotel_subject as introduce,hotel_images as images')
          	 ->where(['is_del'=>0,'is_pass'=>1,'hotel_id'=>$item_id])
          	 ->find();
               if(!empty($result)){
                $imagesArr = Db::name('hotel_img')
                ->where('hotel_id',$item_id)
                ->order('sort desc')
                ->select();
                if(empty($result['images']))$result['images'] = [];
                if(count($imagesArr)>0)
                {
                   foreach ($imagesArr as $key => $value) {
                     if($value['img_path'])
                      $result['images'][] =  addWaterByField($value['img_path']);
                   }
                }
             }
           }
           if($type==3)
          {
          	 $result = Db::name('group_tour')
          	 ->field('gt_subject as introduce,gt_images as images')
          	 ->where(['is_del'=>0,'id'=>$item_id,'is_display'=>0])
          	 ->find();
             if(!empty($result)){ 
                $imagesArr = Db::name('gtour_tour_img')
                ->where(['gt_id'=>$item_id,'is_del'=>0])
                ->order('sort desc')
                ->select();
                if(empty($result['images']))$result['images'] = [];
                if(count($imagesArr)>0)
                {
                   foreach ($imagesArr as $key => $value) { 
                      $result['images'][] =  addWaterByField($value['img_path']);
                   } 
                }
                 
             }
          }
            if(!empty($result)){
               //if(!empty($result['images'])) 
             	 //$result['images'] = explode(',', $result['images']);  
	             $result['all_count'] = $am->getAppCountByItemId($type,$item_id,'',$isImages);
	             $result['good_count'] = $am->getAppCountByItemId($type,$item_id,1,$isImages);
	             $result['bad_count'] = $am->getAppCountByItemId($type,$item_id,2,$isImages);
	             $result['images_count'] = $am->getAppCountByItemId($type,$item_id,3,true);
	             $result['app'] = $am->getAppList($type,$item_id,$page,$limit,$eval_status,$isImages); 
	              return $this->apiReturn('200','成功',$result);

            }
          return $this->apiReturn('200','成功',[]);
		}
   }

}